//
//  Map.h
//  TabulaImaginarius2
//
//  Created by TA2 on 4/17/11.
//  Copyright 2011 __MyCompanyName__. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "Tile.h"
#import "LoadedImages.h"

@interface Map : NSObject <NSCoding> {
	NSString			*name;
	CGSize				size;
	NSString			*backgroundImage;
	NSMutableDictionary *currentlyModifyingTiles;
	NSObject			*currentlyMovingTokenLock;
	NSMutableDictionary *modifiedTiles;
	NSMutableDictionary *tokens;
	CGLayerRef			loadedBackgroundImage;
    BOOL                shouldReloadBackgroundImage;
	CGLayerRef			selectedToken;
    int                 objectIdCount;
    int                 tokenIdCount;
}

@property (retain) NSString *name;
@property (nonatomic) CGSize size;
@property (nonatomic, retain) NSString *backgroundImage;
@property (nonatomic, retain) NSObject *currentlyMovingTokenLock;

- (id)init;
- (NSArray *)getAllModifiedTilePoints;
- (void)modifyTileImage:(UIImage *)image
				atPoint:(CGPoint)point 
			   withPath:(NSString *)path;
- (void)setTileImage:(NSString *)newImageName
			 atPoint:(CGPoint)point;
- (NSArray *)getTilePathsAtPoint:(CGPoint)point forPlayer:(Player *)player forLayer:(int)index;
- (void)addTilePath:(DrawingPath *)path atPoint:(CGPoint)point forPlayer:(Player *)player forLayer:(int)index;
- (void)modifyTilePath:(CGPoint)pathPoint
			   atPoint:(CGPoint)point 
		 withLastPoint:(CGPoint)lastPoint
		  withTileSize:(CGSize)tileSize
		 withLineWidth:(float)lineWidth
			 withColor:(UIColor *)color
			  forLayer:(int)index
         shouldCleanUp:(BOOL)cleanUp;
- (void)modifyTilePath:(CGPoint)pathPoint
			   atPoint:(CGPoint)point 
		 withLastPoint:(CGPoint)lastPoint
		  withTileSize:(CGSize)tileSize
		 withLineWidth:(float)lineWidth
			 withColor:(UIColor *)color
  withColorTexturePath:(NSString *)colorTexturePath
			  forLayer:(int)index
         shouldCleanUp:(BOOL)cleanUp;
- (void)clearMap;
- (void)cancelCurrentPaths;
- (void)scrapCurrentPath:(CGPoint)point;
- (void)submitChangesToTiles:(BOOL)cleanUp;
- (int)getNextId:(NSString *)protocolId;
- (int)getId:(NSString *)protocolId;
- (void)setId:(int)idNumber forProtocolId:(NSString *)protocolId;
- (void)addToken:(Token *) token atPoint:(CGPoint)point withTileSize:(CGSize)tileSize;
- (NSArray *)removeToken:(NSString *)tokenId;
- (void)removeToken:(Token *)token fromPoint:(CGPoint)point;
- (void)clearLoadedBackgroundImage;
- (void)loadBackgroundImage;
- (CGLayerRef)backgroundForPoint:(CGPoint)point;
- (NSString *)backgroundPathForPoint:(CGPoint)point;
- (CGLayerRef)drawingTileForPoint:(CGPoint)point withTileSize:(CGSize)tileSize;
- (void)drawPath:(DrawingPath *)path withTileSize:(CGSize) tileSize forPoint:(CGPoint)point drawAll:(BOOL)drawAll;
- (CGLayerRef)graphicsLayerForMovingTokenAtPoint:(CGPoint)point withViewId:(NSString *)viewId;
- (NSMutableArray *)graphicsLayersForTokenAtPoint:(CGPoint)point withViewId:(NSString *)viewId;
- (Token *)tokenForPoint:(CGPoint)point withViewId:(NSString *)viewId;
- (NSArray *) tokenStackForPoint:(CGPoint)point;
- (BOOL)saveMap;
+ (Map *)loadMap:(NSString *)mapName;
- (void)encodeWithCoder:(NSCoder *)coder;
- (id)initWithCoder:(NSCoder *)coder;
- (void)cleanUpDrawingPaths:(Tile *)tile;
- (CGPoint)convertCoordsToGridCoords:(CGPoint)coords withTileSize:(CGSize)tileSize;


@end
